﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Justin.BI.DBTools;
using Justin.Framework.Helper;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Student s = new Student() { Id = 1000, Name = "zxh", TeacherName = "teacher1" };
            Student s2 = new Student() { Id = 1000, Name = "zxH" };
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("Id", "Id");
            dic.Add("Name", "Name");
            dic.Add("TeacherName", "TId");
            List<Student> s1R = new List<Student>();

            //Entity2EntityDataCompare<Student, Student> compare = new Entity2EntityDataCompare<Student, Student>(dic);

            //int x = compare.Compare(new List<Student>() { s }, new List<Student>() { s, s2 }, dic, s1R, null);
            //richTextBox1.Text = x.ToString() + Environment.NewLine;
            //foreach (var item in s1R)
            //{
            //    richTextBox1.Text += item.Name;
            //}

            Table table = new Table("Student");

            table.CommonFields.Add("Id");
            table.CommonFields.Add("Name");
            table.TranslateFields.Add(new TranslateMapping() { FieldName = "TId", ReferenceFieldName = "Id", DestinationFieldName = "Name", ReferenceTableName = "Teachers" });

            Entity2TableDataCompare<Student, Table> compare2 = new Entity2TableDataCompare<Student, Table>(ExecuteScalar, dic);
            int x = compare2.Compare(new List<Student>() { s }, table, s1R);
            richTextBox1.Text = x.ToString() + Environment.NewLine;
            foreach (var item in s1R)
            {
                richTextBox1.Text += item.Name;
            }

        }
        private SqlConnection Conn;
        public object ExecuteScalar(string sql)
        {
            return SqlHelper.ExecuteScalar(Conn, CommandType.Text, sql, null);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Conn = new SqlConnection("Data Source=.;Initial Catalog=TestDB;Integrated Security=True");
            Conn.Open();

            TreeView tree = new TreeView();

        }
    }
}
